const express = require('express');
//读取cookie必须要引入cookie-parser
const cookieparser = require('cookie-parser');
const cookiesession = require('cookie-session');

var server = express();


//直接砸iServer上边加keys
server.use(cookieparser());
server.use(cookiesession({
	keys:['fdsf','fdsffsdf'],
	name:'sess',
	maxAge: 2*3600*1000
}));
server.use('/',function (req,res) {
	// if(req.session['count']==null){
	// 	req.session['count'] =0;
	// }else{
	// 	req.session['count']++;
	// }
	// res.send(req.session['count']);
	// res.send('ok');


	/**
	 * 	res.session['xxx']
	 delete res.session['xxx'];
	 */
	if(req.session['count']==null){
		req.session['count']=1;
	}else{
		req.session['count']++;
	}

	console.log(req.session['count']);
	var a = req.session['count'].toString();

	//sendStatus(status)
	// delete req.session['sess'];
	res.send(a);

	// var a = req.session['count'].toString();
	// res.send(req.session['count']);
})
server.listen(8080);

